/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.persistencia.dao.impl;

import com.persistencia.dao.PersonaDao;
import com.persistencia.domain.Docente;
import com.persistencia.domain.Persona;
import java.io.Serializable;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.Query;

/**
 *
 * @author SHERLY
 */
public class PersonaDaoImpl extends EntidadDaoImpl<Persona> implements PersonaDao, Serializable{
    
    public int personaMaxId(){
        
        try {
            System.out.println("Entramos a max");
            /*String hql = "select d from "+getEntityClass().getName()+" d " +
                                    "where d.vEstado = :vEstado";
                    
                    Query query = getEntityManager().createQuery(hql);*/
                    em = getEntityManager();
                    Query query = em.createNamedQuery("Persona.buscarMaxId");    
                    return (Integer)query.getSingleResult();
        } catch (Exception ex) {
            Logger.getLogger(DocenteDaoImpl.class.getName()).log(Level.SEVERE, null, ex);
            return -1;
        }
    }
    
    public Persona obtenerUsuario(String usuario){
        
        try {
            System.out.println("Entramos a max");
            /*String hql = "select d from "+getEntityClass().getName()+" d " +
                                    "where d.vEstado = :vEstado";
                    
                    Query query = getEntityManager().createQuery(hql);*/
                    em = getEntityManager();
                    Query query = em.createNamedQuery("Persona.findByVLogin");
                    query.setParameter("vLogin", usuario);
                    return (Persona)query.getSingleResult();
        } catch (Exception ex) {
            Logger.getLogger(DocenteDaoImpl.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }
}
